package com.sky.service.admin.impl;

import com.sky.result.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.constant.StatusConstant;
import com.sky.context.BaseContext;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.mapper.admin.SetMealMapper;
import com.sky.pojo.Setmeal;
import com.sky.service.admin.SetMealService;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
public class SetMealServiceImpl implements SetMealService {
    @Autowired
    private SetMealMapper setMealMapper;

    @Override
    public void insertSetMeal(SetmealDTO setmealDTO) {
        Setmeal setmeal = new Setmeal();
        //映射
        BeanUtils.copyProperties(setmealDTO,setmeal);
        //创建人id
        setmeal.setCreateUser(BaseContext.getCurrentId());
        //更新人id
        setmeal.setUpdateUser(BaseContext.getCurrentId());
        //更新时间
        setmeal.setCreateTime(LocalDateTime.now());
        setmeal.setUpdateTime(LocalDateTime.now());
        //设置状态
        setmeal.setStatus(StatusConstant.DISABLE);
        //调用Mapper层代码
        setMealMapper.insertSetMeal(setmeal);

    }

    @Override
    public PageResult setMealPage(SetmealPageQueryDTO setmealPageQueryDTO) {
        PageHelper.startPage(setmealPageQueryDTO.getPage(),setmealPageQueryDTO.getPageSize());
        Page<SetmealVO> setmeals =setMealMapper.setMealPage(setmealPageQueryDTO);
        return new PageResult(setmeals.getTotal(),setmeals.getResult());
    }

    @Override
    public void deleteSetMeal(List<Integer> ids) {
        setMealMapper.deleteSetMeal(ids);
    }

    @Override
    public SetmealVO querySetMealId(Long setmealId) {
        return setMealMapper.querySetMealId(setmealId);
    }

    @Override
    public void updateSetMeal(SetmealDTO setmealDTO) {
        //setmealDTO.setCategoryId(BaseContext.getCurrentId());
        setMealMapper.updateSetMeal();
    }

    @Override
    public void ActivateAndForbiddenSetMeal(Integer status, Integer id) {
        setMealMapper.ActivateAndForbiddenSetMeal(status,id);
    }
}
